#ifndef CLICKABLELABEL_H
#define CLICKABLELABEL_H
#include <QLabel>
#include <QObject>
#include "../entity.h"
#include <QPixmap>
#include <QMouseEvent>
#include "../world.h"
#include "../unit.h"

class MovableLabel: public QLabel
{

    QWidget *win;
    bool mouseDragging;
    QPoint offset;
    Entity *object;
    bool clicked;

    QString dir;

    QPixmap imageNorth, image_south, imageEast, imageWest,
        SelImageNorth, SelImageSouth, SelImageEast, SelImageWest;

public:
    void updateImgae();
    bool isClicked() {return clicked;}
    void unSelect();
    void unClick() {clicked = false; }
    explicit MovableLabel(QWidget *parent, Entity *obj, QString img, QString selImg);
    ~MovableLabel();

    void mousePressEvent(QMouseEvent *event) {
       if(event->button() == Qt::RightButton){
           if(object->getTeam() != World::instance().getPlayerById(0)->getTeam()){
               Entity *obj = World::instance().getPlayerById(0)->getSelected();
               if(World::instance().getPlayerById(0)->getSelected() != NULL){
                   Unit *sel = dynamic_cast<Unit*>(obj);
                   if(sel != NULL){
                        sel->setAttackTarget(this->getObject());
                   }
               }
           }
       }
       if(event->button() == Qt::LeftButton){
           if(object->getTeam() == 1){
                clicked = true;
                object->setSelected(true);
                World::instance().getPlayerById(0)->setSelected(this->getObject());
                setPixmap(SelImageNorth);
           }
       }
    }
    Entity *getObject() {return object;}
protected:
    bool eventFilter(QObject *obj, QEvent *event);


};



#endif // CLICKABLELABEL_H
